package com.caocaog.market.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.caocaog.market.entity.ImagesCarousel;
import com.caocaog.market.service.ImagesCarouselService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.aspect.annotation.Trim;
import org.jeecg.common.system.base.controller.GenericController;
import org.jeecg.common.system.domain.QueryRequest;
import org.jeecg.common.system.query.PageGenerator;
import org.springframework.web.bind.annotation.*;

/**
 * 轮播图管理
 *
 * @author chechen
 * @date 2021-12-28
 */
@Slf4j
@RestController
@Api(value = "imagesCarousel", tags = ImagesCarouselController.TABLE_MEANING)
@RequestMapping("/imagesCarousel")
public class ImagesCarouselController extends GenericController<ImagesCarousel, ImagesCarouselService> {

    public static final String TABLE_MEANING = "轮播图管理";

    @Trim
    @ApiOperation(value = "分页列表查询", notes = "分页列表查询")
    @GetMapping
    @RequiresPermissions("imagesCarousel:view")
    public Result<?> queryPageList(ImagesCarousel imagesCarousel, QueryRequest queryRequest) {
        Page<ImagesCarousel> page = PageGenerator.createPageSort(queryRequest);
        IPage<ImagesCarousel> pageList = super.service.queryImagesCarouselPage(page, imagesCarousel);
        return Result.OK(pageList);
    }

    @AutoLog(value = TABLE_MEANING + ADD)
    @ApiOperation(value = ADD, notes = ADD)
    @PostMapping
    @RequiresPermissions("imagesCarousel:add")
    public Result<?> add(@RequestBody ImagesCarousel imagesCarousel) {
        return Result.OK(ADD_SUCCESS, super.service.addImagesCarousel(imagesCarousel));
    }

    @AutoLog(value = TABLE_MEANING + EDIT)
    @ApiOperation(value = EDIT, notes = EDIT)
    @PutMapping
    @RequiresPermissions("imagesCarousel:update")
    public Result<?> update(@RequestBody ImagesCarousel imagesCarousel) {
        return Result.OK(EDIT_SUCCESS, super.service.updateImagesCarousel(imagesCarousel));
    }

    @AutoLog(value = TABLE_MEANING + DELETE)
    @ApiOperation(value = DELETE, notes = DELETE)
    @DeleteMapping
    @RequiresPermissions("imagesCarousel:delete")
    public Result<?> delete(@RequestParam("id") Long id) {
        return Result.OK(DELETE_SUCCESS, super.service.deleteImagesCarousel(id));
    }

}
